import 'dart:async';
import 'package:Smart/pages/productor004/project/bluetooth/pop_up_windows/gs_popup_window.dart';
import 'package:flutter/material.dart';
import 'package:Smart/utils/screen_unit/gs_screen_util.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'cubit/gs_bluetooth_cubit.dart';


class GsCountdownVCWidget extends StatefulWidget {
  @override
  _GsCountdownVCWidgetState createState() => _GsCountdownVCWidgetState();
}

class _GsCountdownVCWidgetState extends State<GsCountdownVCWidget> {

  Timer timer;      //倒计时的计时器

  //var _titleTxt = new TextEditingController();
  @override
  void dispose() {
    timer?.cancel();  //销毁计时器
    timer=null;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
        create: (context) => GsBluetoothCubit(),
        child: BlocBuilder<GsBluetoothCubit, GsBluetoothState>(
            builder: (context, state) {
              return Stack(
                children: [
                  Padding(
                      padding:EdgeInsets.fromLTRB(49.w,16.h,49.w,0),
                      //验证码输入框
                      child: TextFormField(
                        //controller: verificationCode,
                        strutStyle: StrutStyle(
                            fontSize: 14.sp
                        ),
                        keyboardType: TextInputType.number, // 唤起键盘输入方式
                        //验证码验证
                        validator: (value) {
                          return value.length < 4 && value.length > 0
                              ? "验证码输入错误，请重新输入"
                              : null;
                        },
                        decoration: InputDecoration(
                            hintText: ('输入验证码'),
                            hintStyle: TextStyle(
                                fontSize: 14.sp
                            )
                        ),
                      )
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(265.sp,13.h,49.sp,0),
                    //发送验证码按钮
                    child: FlatButton(
                      disabledColor: Colors.grey.withOpacity(0.1),  //按钮禁用时的颜色
                      disabledTextColor: Colors.black,     //按钮禁用时的文本颜色
                      textColor: state.isButtonEnable ? Colors.black : Colors.black,       //文本颜色
                      color: state.isButtonEnable ? state.bottonBackColor : state.bottomColor,       //按钮的颜色
                      splashColor: state.isButtonEnable ? Colors.white.withOpacity(0.1) : Colors.transparent,
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(50),
                          side: BorderSide(color: state.bottomBprderColor)
                      ),
                      onPressed: (){
                        setState(() {
                          print(state.count);
                          BlocProvider.of<GsBluetoothCubit>(context).buttonClickListen();

                        });
                      },
                      //按钮显示内容
                      child: Text('${state.buttonText}',style: TextStyle(fontSize: 12.sp,),),
                    ),
                  )
                ],
              );

            }
        )
    );
  }
}